探索 Azure 计算机视觉模型以生成 AI 就绪的 Web 应用程序

Azure 计算机视觉模型是用于构建 AI 就绪 Web 应用程序的强大工具。该模型使开发人员能够从视觉数据中提取见解和含义,并可用于构建广泛的应用程序,从图像分类和对象检测到面部识别和自然语言处理。在本文中,我们将探讨 Azure 计算机视觉模型的功能,以及如何使用它来生成 AI 就绪的 Web 应用程序。我们还将讨论使用此模型的好处,并提供有关如何开始的分步指南。

Azure 计算机视觉模型的功能

Azure 计算机视觉模型是一种基于云的 API,使开发人员能够分析和理解视觉对象数据。此模型可用于:

1.将图像分为不同的类别

Azure 计算机视觉可以将图像分类为不同的类别,例如对象、场景和操作。

例如:对于下图,它将归类为Animal_dog

 

2.检测图像中的物体

Azure 计算机视觉可以检测图像中的对象,包括人、动物和对象。

例如:下图将检测对象 apple,并以 JSON 形式提供响应,如下所示。

 

JSON的

{   "objects":[      {         "rectangle":{            "x":730,            "y":66,            "w":135,            "h":85         },         "object":"Apple",         "confidence":0.98      }}

3.识别人脸并提取面部特征

Azure 计算机视觉可以识别人脸并提取人脸特征,例如年龄、性别和情绪。

图像来自Microsoft

JSON的

{    "faces": [        {            "age": 11,            "gender": "Male",            "faceRectangle": {                "top": 62,                "left": 22,                "width": 45,                "height": 45            }        },        {            "age": 11,            "gender": "Female",            "faceRectangle": {                "top": 127,                "left": 240,                "width": 42,                "height": 42            }        },        {            "age": 37,            "gender": "Female",            "faceRectangle": {                "top": 55,                "left": 200,                "width": 41,                "height": 41            }        },        {            "age": 41,            "gender": "Male",            "faceRectangle": {                "top": 45,                "left": 103,                "width": 39,                "height": 39            }        }    ],    "requestId": "3a383cbe-1a05-4104-9ce7-1b5cf352b239",    "metadata": {        "height": 230,        "width": 300,        "format": "Png"    }}

4.从图像中提取文本

Azure 计算机视觉可以从图像中提取文本,包括手写文本和打印文本。

5.生成图像描述

Azure 计算机视觉可以生成图像描述,包括标题和标记。

使用 Azure 计算机视觉模型的好处

使用 Azure 计算机视觉模型可以为 Web 应用程序带来许多好处,包括:

可以通过导航到 Azure AI |视觉工作室。

使用 Azure 计算机视觉模型生成 AI 就绪 Web 应用程序的分步指南

下面是使用 Azure 计算机视觉模型生成 AI 就绪 Web 应用程序的分步指南:

  1. 注册 Azure:通过导航到 AI Vision Studio 链接,创建一个 Azure 帐户并订阅计算机视觉服务。复制稍后在代码中使用的 Key 和 Endpoint,以调用计算机视觉客户端 SDK。

  2. 选择编程语言:选择 Python、Java 或 C# 等编程语言来构建应用程序。我在下面的代码示例中使用了 NodeJS。

  3. 安装 Azure 计算机视觉 SDK:安装适用于所选编程语言的 Azure 计算机视觉 SDK。

  4. 上传图像:将图像上传到 Azure 存储帐户,可在代码中使用该帐户进行分析

  5. 分析图像:使用 Azure 计算机视觉 API 分析图像并提取见解。

  6. 与您的 Web 应用程序集成:将提取的见解与您的 Web 应用程序集成,以提供更加个性化和引人入胜的体验

下面的代码是使用 NodeJS 编写的,我使用计算机视觉客户端 SDK 分析了包含水果和蔬菜的图像,并提供了有关检测到的对象和响应的输出。

JavaScript的

'use strict';var http = require('http');var port = process.env.PORT || 1337;
const { ComputerVisionClient } = require("@azure/cognitiveservices-computervision");const { ApiKeyCredentials } = require("@azure/ms-rest-js");
const key = '<subscription Key>';const endpoint = '<computervision endpoint>';
const credentials = new ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': key } });const client = new ComputerVisionClient(credentials, endpoint);
http.createServer(async function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); //res.end('Hello World\n');
// Define the URL of the image uploaded to storage account which you want to analyze const imageUrl = '<imageUrl>';
// Call the function to analyze the image const result = await analyzeImage(imageUrl, { visualFeatures: ['Objects'] });
// Assuming 'result' is the response from the analyzeImage call if (result.objects && result.objects.length > 0) { const fruitsAndVeggies = result.objects.filter(obj => obj.object.toLowerCase().includes('fruit') || obj.object.toLowerCase().includes('vegetable')); console.log("Detected fruits and vegetables:", fruitsAndVeggies); } else { console.log("No fruits or vegetables detected."); }
// Send the analysis result as the response res.end(`Image Analysis Result:\n${JSON.stringify(result, null, 2)}`);}).listen(port);
async function analyzeImage(url) { try { const result = await client.analyzeImage(url, { visualFeatures: ['Categories', 'Description', 'Objects'] }); console.log("Image analysis result:", result); return result; } catch (error) { console.error("An error occurred while analyzing the image:", error); return error; }}

 

结论

Azure 计算机视觉模型是用于构建 AI 就绪 Web 应用程序的强大工具。通过利用此模型,开发人员可以从视觉数据中提取见解和意义,并为用户提供更加个性化和引人入胜的体验。Azure 计算机视觉模型具有广阔的区域、众多优势和易用性,是希望构建智能 AI 就绪 Web 应用程序的企业的理想选择。


本文由“公众号文章抓取器”生成,请忽略上文所有联系方式或指引式信息。有问题可以联系:五人工作室,官网:www.Wuren.Work,QQ微信同号1976.424.585